     /********************************************************************************/
    /*************** Firm's Source Country or Project Characteristics? **************/
   /* Survey Experiments on Preferences for Chinese Investment in the Global South */
  /********************************************************************************/
 /****************** David Bulman, Ning Leng, and Kerry Ratigan ******************/
/********************************************************************************/

/* This file should be used with the SourceCountryProjectCharacteristics_CleanData.dta file.
It reshapes and cleans the data for conjoint analysis. */ 

use SourceCountryProjectCharacteristics_CleanData.dta

/* RESHAPE DATA LONG FOR CONJOINT ANALYSIS */

forvalues i=1/5 {
	rename conjoint_`i' choice`i'
	}

reshape long choice, i(responseid) j(task)
gen rating1=.
gen rating2=.
reshape long rating, i(responseid task) j(project)
drop rating

gen selected=1 if project==choice
replace selected=0 if project!=choice

/* TRANSLATE ATTRIBUTE NAMES INTO ENGLISH */

/* Spanish */
forvalues i=1/5 {
	forvalues j=1/7 {
		replace c`i'_attrib`j'_name="Firm's country of origin" if c`i'_attrib`j'_name=="País de origen de la empresa"
		replace c`i'_attrib`j'_name="Project type" if c`i'_attrib`j'_name=="Sector del proyecto"
		replace c`i'_attrib`j'_name="Local job creation" if c`i'_attrib`j'_name=="Generación de empleo local"
		replace c`i'_attrib`j'_name="Migrant workers" if c`i'_attrib`j'_name=="Trabajadores migrantes"
		replace c`i'_attrib`j'_name="History of labor rights violations" if c`i'_attrib`j'_name=="Antecedentes de infracciones laborales" 
		replace c`i'_attrib`j'_name="Plan to reduce environmental impact" if c`i'_attrib`j'_name=="Plan para disminuir el impacto ambiental"
		replace c`i'_attrib`j'_name="Accusations of bribing local politicians" if c`i'_attrib`j'_name=="Denuncias por sobornar a políticos locales"
		}
	}

/* Portuguese */
forvalues i=1/5 {
	forvalues j=1/7 {
		replace c`i'_attrib`j'_name="Firm's country of origin" if c`i'_attrib`j'_name=="País de origem da empresa"
		replace c`i'_attrib`j'_name="Project type" if c`i'_attrib`j'_name=="Tipo de projeto"
		replace c`i'_attrib`j'_name="Local job creation" if c`i'_attrib`j'_name=="Criação de empregos locais"
		replace c`i'_attrib`j'_name="Migrant workers" if c`i'_attrib`j'_name=="Trabalhadores imigrantes"
		replace c`i'_attrib`j'_name="History of labor rights violations" if c`i'_attrib`j'_name=="Histórico de violações de direitos trabalhistas" 
		replace c`i'_attrib`j'_name="Plan to reduce environmental impact" if c`i'_attrib`j'_name=="Plano para reduzir o impacto ambiental"
		replace c`i'_attrib`j'_name="Accusations of bribing local politicians" if c`i'_attrib`j'_name=="Acusações de suborno a políticos locais"
		}
	}
	
	
/* Indonesian */
forvalues i=1/5 {
	forvalues j=1/7 {
		replace c`i'_attrib`j'_name="Firm's country of origin" if c`i'_attrib`j'_name=="Negara asal perusahaan"
		replace c`i'_attrib`j'_name="Project type" if c`i'_attrib`j'_name=="Jenis proyek"
		replace c`i'_attrib`j'_name="Local job creation" if c`i'_attrib`j'_name=="Penciptaan lapangan kerja lokal"
		replace c`i'_attrib`j'_name="Migrant workers" if c`i'_attrib`j'_name=="Pekerja migran"
		replace c`i'_attrib`j'_name="History of labor rights violations" if c`i'_attrib`j'_name=="Riwayat pelanggaran hak-hak buruh" 
		replace c`i'_attrib`j'_name="Plan to reduce environmental impact" if c`i'_attrib`j'_name=="Rencana untuk mengurangi dampak lingkungan"
		replace c`i'_attrib`j'_name="Accusations of bribing local politicians" if c`i'_attrib`j'_name=="Tuduhan menyuap politisi lokal"
		}
	}


/* Malaysian */
forvalues i=1/5 {
	forvalues j=1/7 {
		replace c`i'_attrib`j'_name="Firm's country of origin" if c`i'_attrib`j'_name=="Negara asal firma"
		replace c`i'_attrib`j'_name="Project type" if c`i'_attrib`j'_name=="Jenis projek"
		replace c`i'_attrib`j'_name="Local job creation" if c`i'_attrib`j'_name=="Penciptaan pekerjaan tempatan"
		replace c`i'_attrib`j'_name="Migrant workers" if c`i'_attrib`j'_name=="Pekerja migran" 
		replace c`i'_attrib`j'_name="History of labor rights violations" if c`i'_attrib`j'_name=="Sejarah pelanggaran hak buruh"
		replace c`i'_attrib`j'_name="Plan to reduce environmental impact" if c`i'_attrib`j'_name=="Rancangan untuk mengurangkan kesan alam sekitar"
		replace c`i'_attrib`j'_name="Accusations of bribing local politicians" if c`i'_attrib`j'_name=="Tuduhan merasuah ahli politik tempatan"
		}
	}

/* Chinese */
forvalues i=1/5 {
	forvalues j=1/7 {
		replace c`i'_attrib`j'_name="Firm's country of origin" if c`i'_attrib`j'_name=="公司的原属国"
		replace c`i'_attrib`j'_name="Project type" if c`i'_attrib`j'_name=="投资计划所在的行业"
		replace c`i'_attrib`j'_name="Local job creation" if c`i'_attrib`j'_name=="产生的本地工作机会"
		replace c`i'_attrib`j'_name="Migrant workers" if c`i'_attrib`j'_name=="来自公司原属国的外籍劳工"
		replace c`i'_attrib`j'_name="History of labor rights violations" if c`i'_attrib`j'_name=="剥削劳工的前科"
		replace c`i'_attrib`j'_name="Plan to reduce environmental impact" if c`i'_attrib`j'_name=="有无减少对环境负面影响的计划"
		replace c`i'_attrib`j'_name="Accusations of bribing local politicians" if c`i'_attrib`j'_name=="有无与当地政客进行腐败交易的前科"
		}
	}


	
	
/* MATCH AND ENCODE PROJECT ATTRIBUTES */

gen source=""
gen sector=""
gen jobs=""
gen migrant=""
gen labor=""
gen environment=""
gen corruption=""


forvalues i=1/5 {
	forvalues j=1/7 {
		forvalues k=1/2 {
			replace source=c`i'_attrib`j'_project`k' if c`i'_attrib`j'_name=="Firm's country of origin" & task==`i' & project==`k'
			replace sector=c`i'_attrib`j'_project`k' if c`i'_attrib`j'_name=="Project type" & task==`i' & project==`k'
			replace jobs=c`i'_attrib`j'_project`k' if c`i'_attrib`j'_name=="Local job creation" & task==`i' & project==`k'
			replace migrant=c`i'_attrib`j'_project`k' if c`i'_attrib`j'_name=="Migrant workers" & task==`i' & project==`k'
			replace labor=c`i'_attrib`j'_project`k' if c`i'_attrib`j'_name=="History of labor rights violations" & task==`i' & project==`k'
			replace environment=c`i'_attrib`j'_project`k' if c`i'_attrib`j'_name=="Plan to reduce environmental impact" & task==`i' & project==`k'
			replace corruption=c`i'_attrib`j'_project`k' if c`i'_attrib`j'_name=="Accusations of bribing local politicians" & task==`i' & project==`k'
			}
		}
	}

/* Remove country names from migrant attribute */
replace migrant=subinstr(migrant, " China", "", .)
replace migrant=subinstr(migrant, " India", "", .)
replace migrant=subinstr(migrant, " Japan", "", .)
replace migrant=subinstr(migrant, " Saudi Arabia", "", .)
replace migrant=subinstr(migrant, " United States", "", .)

/* Translate attributes */

	/*Spanish*/
	replace migrant=subinstr(migrant, " China", "", .)
	replace migrant=subinstr(migrant, " India", "", .)
	replace migrant=subinstr(migrant, " Japón", "", .)
	replace migrant=subinstr(migrant, " Arabia Saudita", "", .)
	replace migrant=subinstr(migrant, " Estados Unidos", "", .)

	replace source="United States" if source=="Estados Unidos"
	replace source="Japan" if source=="Japón"
	replace source="Saudi Arabia" if source=="Arabia Saudita"
	replace sector="Agriculture" if sector=="Agricultura"
	replace sector="Grocery store chain" if sector=="Cadena de supermercados"
	replace sector="Mining" if sector=="Minería"
	replace sector="Solar power plant" if sector=="Planta de energía solar"
	replace sector="Telecommunications network" if sector=="Red de telecomunicaciones"
	replace sector="Textile manufacturing" if sector=="Fabricación textil"
	replace jobs="1000 jobs" if jobs=="1000 empleos"
	replace jobs="50 jobs" if jobs=="50 empleos"
	replace migrant="20 workers from" if migrant=="20 trabajadores de"
	replace migrant="200 workers from" if migrant=="200 trabajadores de"
	replace labor="No history" if labor=="Sin antecedentes"
	replace labor="Past violations" if labor=="Violaciones previas"
	replace environment="None" if environment=="Ninguno"
	replace environment="Best practice plan" if environment=="Plan de las mejores prácticas"
	replace corruption="No" if corruption=="No"
	replace corruption="Yes" if corruption=="Sí"

	/*Portuguese*/
	replace migrant=subinstr(migrant, " Índia", "", .)
	replace migrant=subinstr(migrant, " Japão", "", .)
	replace migrant=subinstr(migrant, " Arábia Saudita", "", .)
	replace migrant=subinstr(migrant, " Estados Unidos", "", .)
	
	replace source="India" if source=="Índia"
	replace source="Japan" if source=="Japão"
	replace source="Saudi Arabia" if source=="Arábia Saudita"
	replace sector="Agriculture" if sector=="Agricultura"
	replace sector="Grocery store chain" if sector=="Rede de supermercados"
	replace sector="Mining" if sector=="Mineração"
	replace sector="Solar power plant" if sector=="Planta de energia solar"
	replace sector="Telecommunications network" if sector=="Rede de telecomunicações"
	replace sector="Textile manufacturing" if sector=="Fabricação têxtil"
	replace jobs="1000 jobs" if jobs=="1000 empregos"
	replace jobs="50 jobs" if jobs=="50 empregos"
	replace migrant="20 workers from" if migrant=="20 trabalhadores de"
	replace migrant="20 workers from" if migrant=="20 trabalhadores da"
	replace migrant="20 workers from" if migrant=="20 trabalhadores do"
	replace migrant="20 workers from" if migrant=="20 trabalhadores dos"
	replace migrant="200 workers from" if migrant=="200 trabalhadores de"	
	replace migrant="200 workers from" if migrant=="200 trabalhadores da"	
	replace migrant="200 workers from" if migrant=="200 trabalhadores do"
	replace migrant="200 workers from" if migrant=="200 trabalhadores dos"
	replace labor="No history" if labor=="Sem histórico de violações"
	replace labor="Past violations" if labor=="Violações passadas confirmadas"
	replace environment="None" if environment=="Nenhum"
	replace environment="Best practice plan" if environment=="Plano de melhores práticas"
	replace corruption="No" if corruption=="Não"
	replace corruption="Yes" if corruption=="Sim"
	
	
	/*Indonesian*/
	replace migrant=subinstr(migrant, " Tiongkok", "", .)
	replace migrant=subinstr(migrant, " India", "", .)
	replace migrant=subinstr(migrant, " Jepang", "", .)
	replace migrant=subinstr(migrant, " Arab Saudi", "", .)
	replace migrant=subinstr(migrant, " Amerika Serikat", "", .)

	replace source="China" if source=="Tiongkok"
	replace source="United States" if source=="Amerika Serikat"
	replace source="Japan" if source=="Jepang"
	replace source="Saudi Arabia" if source=="Arab Saudi"
	replace sector="Agriculture" if sector=="Pertanian"
	replace sector="Grocery store chain" if sector=="Jaringan toko bahan makanan"
	replace sector="Mining" if sector=="Pertambangan"
	replace sector="Solar power plant" if sector=="Pembangkit listrik tenaga surya"
	replace sector="Telecommunications network" if sector=="Jaringan telekomunikasi"
	replace sector="Textile manufacturing" if sector=="Manufaktur tekstil"
	replace jobs="1000 jobs" if jobs=="1000 pekerjaan"
	replace jobs="50 jobs" if jobs=="50 pekerjaan"
	replace migrant="20 workers from" if migrant=="20 pekerja dari"
	replace migrant="200 workers from" if migrant=="200 pekerja dari"
	replace labor="No history" if labor=="Tidak ada sejarah"
	replace labor="Past violations" if labor=="Pelanggaran di masa lalu"
	replace environment="None" if environment=="Tidak ada"
	replace environment="Best practice plan" if environment=="Rencana praktik terbaik"
	replace corruption="No" if corruption=="Tidak"
	replace corruption="Yes" if corruption=="Ya"

	/*Malaysian*/
	replace migrant=subinstr(migrant, " Jepun", "", .)
	replace migrant=subinstr(migrant, " Amerika Syarikat", "", .)

	replace source="United States" if source=="Amerika Syarikat"
	replace source="Japan" if source=="Jepun"
	replace sector="Agriculture" if sector=="Pertanian"
	replace sector="Grocery store chain" if sector=="Rangkaian kedai runcit"
	replace sector="Mining" if sector=="Perlombongan"
	replace sector="Solar power plant" if sector=="Loji tenaga suria"
	replace sector="Telecommunications network" if sector=="Rangkaian telekomunikasi"
	replace sector="Textile manufacturing" if sector=="Pembuatan tekstil"
	replace jobs="1000 jobs" if jobs=="1000 pekerjaan"
	replace jobs="50 jobs" if jobs=="50 pekerjaan"
	replace migrant="20 workers from" if migrant=="20 pekerja dari"
	replace migrant="200 workers from" if migrant=="200 pekerja dari"
	replace labor="No history" if labor=="Tiada sejarah"
	replace labor="Past violations" if labor=="Pelanggaran lampau"
	replace environment="None" if environment=="Tiada"
	replace environment="Best practice plan" if environment=="Pelan amalan terbaik"
	replace corruption="No" if corruption=="Tidak"
	replace corruption="Yes" if corruption=="Ya"
	
	/*Chinese*/

	replace source="China" if source=="中国"
	replace source="United States" if source=="美国"
	replace source="Japan" if source=="日本"
	replace source="India" if source=="印度"
	replace source="Saudi Arabia" if source=="沙特阿拉伯"
	replace sector="Agriculture" if sector=="农业"
	replace sector="Grocery store chain" if sector=="连锁超市"
	replace sector="Mining" if sector=="采矿业"
	replace sector="Solar power plant" if sector=="太阳能发电"
	replace sector="Telecommunications network" if sector=="电信通讯" 
	replace sector="Textile manufacturing" if sector=="纺织业"
	replace jobs="1000 jobs" if jobs=="1000个工作机会"
	replace jobs="50 jobs" if jobs=="50个工作机会"
	replace migrant="20 workers from" if migrant=="20个"
	replace migrant="200 workers from" if migrant=="200个"
	replace labor="No history" if labor=="没有前科"
	replace labor="Past violations" if labor=="有前科"
	replace environment="None" if environment=="无计划"
	replace environment="Best practice plan" if environment=="有计划"
	replace corruption="No" if corruption=="没有前科"
	replace corruption="Yes" if corruption=="有前科"
	
	
/* Numerically encode attributes and specify mapping that we want*/
label define labels_country /// 
		   1 "United States" ///
           2 "China" ///
           3 "Japan" ///
           4 "Saudi Arabia" ///
           5 "India"
label define labels_sector ///
           1 "Agriculture" ///
           2 "Grocery store chain" ///
           3 "Mining" ///
           4 "Solar power plant" ///
           5 "Telecommunications network" ///
           6 "Textile manufacturing"
label define labels_jobs ///
           1 "50 jobs" ///
           2 "1000 jobs"
label define labels_migrant ///
           1 "20 workers from" ///
           2 "200 workers from"
label define labels_labor ///
           1 "No history" ///
           2 "Past violations"
label define labels_environment ///
           1 "None" ///
           2 "Best practice plan"
label define labels_corruption ///
           1 "No" ///
           2 "Yes"

encode source, gen(att_country) label(labels_country)
encode sector, gen(att_sector) label(labels_sector)
encode jobs, gen(att_jobs) label(labels_jobs)
encode migrant, gen(att_migrant) label(labels_migrant)
encode labor, gen(att_labor) label(labels_labor)
encode environment, gen(att_environment) label(labels_environment)
encode corruption, gen(att_corruption) label(labels_corruption)

label variable att_country "Firm's country of origin"
label variable att_sector "Sector"
label variable att_jobs "Job creation"
label variable att_migrant "Migrant labor"
label variable att_labor "Labor rights violations"
label variable att_environment "Environmental mitigation plans"
label variable att_corruption "Bribery accusations"

drop source sector jobs migrant labor environment corruption *_name *_project1 *_project2	

save SourceCountryProjectCharacteristics_ReshapedData.dta, replace
